/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.persistence.memory;

import apus.entity.Period;
import apus.persistence.PeriodDAO;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author  Maxim Vasilevsky
 * @author  Roman Dyatkovsky
 * @since APUS v0.2
 * @see AbstractMemoryDAO
 * @see PeriodDAO
 */
public class MemoryPeriodDAO extends AbstractMemoryDAO<Period> implements PeriodDAO{
    
    private static Map<Integer,Period> dataSource = new HashMap<>();
    private static Integer counter = 1;
      
    @Override
    protected Map<Integer, Period> getDataSource() {
        return dataSource;
    }

    @Override
    protected Integer getAndIncreaseCounter() {
        return counter++;
    }

    @Override
    public Period readByStartAndEndDates(Date start, Date end) {
        for (Period period: dataSource.values()){
            if ((period.getStartDate().equals(start))&&(period.getEndDate().equals(end))){
                return period;
            }
        }
        return null;
    }
 
}
